package com.zc.controller;

import com.zc.common.BaseResult;
import com.zc.model.Payment;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @description:
 * @author: cong
 * @create: 2024/10/9
 */
@RestController
public class OrderController {
    public static final String PAYMENT_URL = "http://cloud-payment";

    @Resource
    private DiscoveryClient discoveryClient;

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/order/{id}")
    public BaseResult<Payment> getOrderPayment(@PathVariable("id") Long id) {
        for (String service : discoveryClient.getServices()) {
            System.out.println("service:" + service);
        }
        return restTemplate.getForObject(PAYMENT_URL + "/query/" + id, BaseResult.class);
    }

}
